(deftemplate senzor(slot denumire)(slot incapere))
(deftemplate aparat(slot denumire)(slot senzor)(slot energie))
(deftemplate do (slot id)(slot persoana)(slot ora (type INTEGER)) (slot minut (type INTEGER))(slot actiune) (slot ap ))

/* senzorii */
(assert (senzor (denumire s1) (incapere bucatarie)))
(assert (senzor (denumire s2) (incapere bucatarie)))

(assert (senzor (denumire s3) (incapere baie)))
(assert (senzor (denumire s4) (incapere baie)))

(assert (senzor (denumire s5) (incapere sufragerie)))
(assert (senzor (denumire s6) (incapere sufragerie)))
(assert (senzor (denumire s7)(incapere sufragerie)))
(assert (senzor (denumire s8) (incapere sufragerie)))

(assert (senzor (denumire s9)(incapere hol)))
(assert (senzor (denumire s10) (incapere hol)))
(assert (senzor (denumire s11)(incapere hol)))

/* introduc aparatele legate de senzori */

(assert (aparat (denumire cmicro)(senzor s1)(energie 5))) /* priza de la bucatarie*/
(assert (aparat (denumire bec1)(senzor s2)(energie 7))) /* lumina la bucatarie*/

(assert (aparat (denumire mspalat)(senzor s3)(energie 8))) /* priza baie */
(assert (aparat (denumire bec2)(senzor s4)(energie 7))) /* becul de la baie*/

(assert (aparat (denumire televizor)(senzor s5)(energie 6))) /* priza televizor */
(assert (aparat (denumire calculator)(senzor s6)(energie 9))) /* priza calculator */
(assert (aparat (denumire fiercalcat)(senzor s7)(energie 3))) /*priza sufragterie */
(assert (aparat(denumire bec3)(senzor s8)(energie 8))) /* bec sufragerie */

(assert (aparat (denumire bec4) (senzor s9)(energie 8))) /* bec hol */
(assert (aparat (denumire feon) (senzor s10)(energie 5))) /* priza hol */
(assert (aparat (denumire frigider)(senzor s11)(energie 11)))   /* priza frigider */ 



/* scenariul */

(assert (do (id 1) (persoana Vasile)(ora 07) (minut 0) (actiune start)(ap bec2)))
(assert (do (id 1) (persoana Vasile) (ora 07) (minut 15)(actiune stop)(ap bec2)))
(assert (do (id 2) (persoana Maria)(ora 07)(minut 19)(actiune start)(ap bec1)))
(assert (do (id 3)(persoana Maria)(ora 07)(minut 20)(actiune start)(ap cmicro)))
(assert (do (id 3)(persoana Maria)(ora 07)(minut 22)(actiune stop)(ap cmicro)))
(assert (do (id 4)(persoana Vasile)(ora 07)(minut 40)(actiune start)(ap bec4)))
(assert (do (id 2)(persoana Maria)(ora 07)(minut 45)(actiune stop)(ap bec1)))
(assert (do (id 4)(persoana Maria)(ora 08)(minut 0)(actiune stop)(ap bec4)))
(assert (do (id 5)(persoana Vasile)(ora 08)(minut 01)(actiune start)(ap bec2)))
(assert (do (id 6)(persoana Vasile)(ora 08)(minut 20)(actiune start)(ap bec3)))
(assert (do (id 7)(persoana Ion)(ora 08)(minut 30)(actiune start)(ap cmicro)))
(assert (do (id 7)(persoana Ion)(ora 08)(minut 32)(actiune stop)(ap cmicro)))
(assert (do (id 5)(persoana Maria)(ora 08)(minut 35)(actiune stop)(ap bec2)))
(assert (do (id 8)(persoana Ion)(ora 08)(minut 40)(actiune start)(ap bec2)))
(assert (do (id 9)(persoana Vasile)(ora 08)(minut 45)(actiune start)(ap bec4)))
(assert (do (id 6)(persoana Maria)(ora 08)(minut 48)(actiune stop)(ap bec3)))
(assert (do (id 9)(persoana Maria)(ora 08)(minut 50)(actiune stop)(ap bec4)))
(assert (do (id 8)(persoana Ion)(ora 08)(minut 51)(actiune stop)(ap bec2)))
(assert (do (id 10)(persoana Ion)(ora 08)(minut 52)(actiune start)(ap calculator)))
(assert (do (id 11)(persoana Ion)(ora 10)(minut 35)(actiune start)(ap televizor)))
(assert (do (id 12)(persoana Ion)(ora 11)(minut 20)(actiune start)(ap bec1)))
(assert (do (id 12)(persoana Ion)(ora 11)(minut 22)(actiune stop)(ap bec1)))
(assert (do (id 13)(persoana Ion)(ora 12)(minut 05)(actiune start)(ap bec2)))
(assert (do (id 13)(persoana Ion)(ora 12)(minut 10)(actiune stop)(ap bec2)))
(assert (do (id 14)(persoana Ion)(ora 12)(minut 11)(actiune start)(ap bec4)))
(assert (do (id 14)(persoana Ion)(ora 12)(minut 20)(actiune stop)(ap bec4)))
(assert (do (id 15)(persoana Ion)(ora 12)(minut 21)(actiune start)(ap fiercalcat)))
(assert (do (id 15)(persoana Ion)(ora 12)(minut 27)(actiune stop)(ap fiercalcat)))
(assert (do (id 11)(persoana Ion)(ora 12)(minut 28)(actiune stop)(ap televizor)))
(assert (do (id 10)(persoana Ion)(ora 08)(minut 28)(actiune stop)(ap calculator)))
(assert (do (id 16)(persoana Ion)(ora 12)(minut 29)(actiune start)(ap bec4)))
(assert (do (id 16)(persoana Ion)(ora 12)(minut 31)(actiune stop)(ap bec4)))
(assert (do (id 17)(persoana Maria)(ora 17)(minut 30)(actiune start)(ap bec4)))
(assert (do (id 17)(persoana Maria)(ora 17)(minut 32)(actiune stop)(ap bec4)))
(assert (do (id 18)(persoana Maria)(ora 17)(minut 33)(actiune start)(ap bec2)))
(assert (do (id 19)(persoana Maria)(ora 17)(minut 50)(actiune start)(ap mspalat)))
(assert (do (id 18)(persoana Maria)(ora 17)(minut 51)(actiune stop)(ap bec2)))
(assert (do (id 20)(persoana Maria)(ora 18)(minut 0)(actiune start)(ap cmicro)))
(assert (do (id 20)(persoana Maria)(ora 18)(minut 3)(actiune stop)(ap cmicro)))
(assert (do (id 21)(persoana Maria)(ora 18)(minut 15)(actiune start)(ap televizor)))
(assert (do (id 22)(persoana Vasile)(ora 18)(minut 45)(actiune start)(ap bec4)))
(assert (do (id 22)(persoana Vasile)(ora 18)(minut 47)(actiune stop)(ap bec4)))
(assert (do (id 23)(persoana Vasile)(ora 18)(minut 48)(actiune start)(ap bec2)))
(assert (do (id 23)(persoana Vasile)(ora 18)(minut 55)(actiune stop)(ap bec2)))
(assert (do (id 21)(persoana Maria)(ora 18)(minut 57)(actiune stop)(ap televizor)))
 (assert (do (id 24)(persoana Maria)(ora 18)(minut 49)(actiune start)(ap bec1)))
(assert (do (id 25)(persoana Maria)(ora 19)(minut 40)(actiune start)(ap bec2)))
(assert (do (id 19)(persoana Maria)(ora 19)(minut 41)(actiune stop)(ap mspalat)))
(assert (do(id 26)(persoana Ion)(ora 19)(minut 50)(actiune start)(ap bec4)))
(assert (do(id 26)(persoana Ion)(ora 19)(minut 52)(actiune stop)(ap bec4)))
(assert (do (id 28)(persoana Maria)(ora 20)(minut 10)(actiune start)(ap feon)))
(assert (do (id 24)(persoana Ion)(ora 20)(minut 19)(actiune stop)(ap bec1)))
(assert (do (id 29)(persoana Ion)(ora 20)(minut 14)(actiune start)(ap calculator)))
(assert (do (id 28)(persoana Maria)(ora 20)(minut 20)(actiune stop)(ap feon)))
(assert (do (id 25)(persoana Ion)(ora 20)(minut 33)(actiune stop)(ap bec2)))
(assert (do (id 30)(persoana Maria)(ora 20)(minut 34)(actiune start)(ap televizor)))
(assert (do (id 29)(persoana Ion)(ora 22)(minut 30)(actiune stop)(ap calculator)))
(assert (do (id 30)(persoana Vasile)(ora 22)(minut 30)(actiune stop)(ap televizor)))



(load-function userFunction)
(defrule afiseaza
    (do (id ?i)(ora ?h1) (minut ?m1)(actiune start) (ap ?a ))
    (do (id ?i)(ora ?h2) (minut ?m2)(actiune stop) (ap ?a ))
    (aparat (denumire ?a) (energie ?e) (senzor ?s))
    
    =>
    (energie ?h1 ?m1 ?h2 ?m2 ?e ?s)
    )(run)